<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script>
        // 倒计时 距离下周一上课还有多长时间； 2021-11-22 8:30

        var time2 = new Date("2021-11-22 8:30");
        function fn() {
            var time1 = new Date(); //现在的时间
            //获取两个时间的时间戳
            var time1tamp = time1.getTime() / 1000;
            var time2tamp = time2.getTime() / 1000;
            //   console.log(time1tamp);

            //获取这两个时间的时间段
            var intervalTime = parseInt(time2tamp - time1tamp);
            //   console.log(intervalTime);
            //计算剩余的天数
            var day = parseInt(intervalTime / 3600 / 24);
            //   console.log(day);
            //计算剩余的小时
            var hour = parseInt(intervalTime / 3600) % 24;
            //   console.log(hour);
            //计算剩余的分钟
            var minute = parseInt(intervalTime / 60) % 60;
            //   console.log(minute);
            //计算剩余的秒数
            var second = parseInt(intervalTime % 60);
            //   console.log(second);
            var str = `距离周一还有${day}天${hour}时${minute}分${second}秒`;
            document.body.innerHTML = str;
        }
        setInterval(function () {
            fn();
        }, 1000);
    </script>
</body>

</html>